#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>

using namespace std;

class Solution
{
public:
	string multiply(string num1, string num2)
	{
		if (num1 == "0" || num2 == "0")
		{
			return "0";
		}

		string res = "0";
		int end1 = num1.size() - 1, end2 = num2.size() - 1;
		int next = 0;

		for (int i = end2; i >= 0 ;i--)
		{
			string cur;
			for (int j = end2; j > i; j--)
			{
				cur.push_back('0');
			}

			int val2 = num2[i] - '0';
			for (int j = end1; j >= 0; j--)
			{
				int val1 = num1[j] - '0';
				int tmp = val1 * val2 + next;

				next = tmp / 10;
				tmp %= 10;

				cur.push_back(tmp + '0');
			}

			while (next != 0)
			{
				cur.push_back(next % 10 + '0');
				next /= 10;
			}

			reverse(cur.begin(), cur.end());

			res = addstring(res, cur);
		}
		return res;
	}

	string addstring(string num1, string num2)
	{
		string res;
		int end1 = num1.size() - 1, end2 = num2.size() - 1;
		int next = 0;

		while (end1 >= 0 || end2 >= 0)
		{
			int val1 = end1 >= 0 ? num1[end1--] - '0' : 0;
			int val2 = end2 >= 0 ? num2[end2--] - '0' : 0;
			int ret = val1 + val2 + next;

			next = ret / 10;
			ret %= 10;

			res.push_back(ret + '0');
		}

		if (next != 0)
		{
			res.push_back(next + '0');
		}

		reverse(res.begin(), res.end());

		return res;
	}
};

int main()
{
	Solution solution;

	string arr1 = "123", arr2 = "234";
	string res = solution.addstring(arr1, arr2);

	cout << res << endl;

	res = solution.multiply(arr1, arr2);

	cout << res << endl;
	return 0;
}